home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / memccpy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  799 b   |  48 lines

  1. #include "lib.h"
  2.  
  3. /*
  4.  * memccpy - copy bytes up to a certain char
  5.  *
  6.  * CHARBITS should be defined only if the compiler lacks "unsigned char".
  7.  * It should be a mask, e.g. 0377 for an 8-bit machine.
  8.  */
  9.  
  10. #ifdef NULL
  11. #undef NULL
  12. #endif
  13.  
  14. #define    NULL    0
  15.  
  16. #ifndef CHARBITS
  17. #    define    UNSCHAR(c)    ((unsigned char)(c))
  18. #    define  uchar        unsigned char
  19. #else
  20. #    define    UNSCHAR(c)    ((c)&CHARBITS)
  21. #    define  uchar        char
  22. #endif
  23.  
  24. _VOIDSTAR
  25. memccpy(dst, src, ucharstop, size)
  26. _VOIDSTAR dst;
  27. _CONST _VOIDSTAR src;
  28. int ucharstop;
  29. _SIZET size;
  30. {
  31.     register char *d;
  32.     register _CONST char *s;
  33.     register _SIZET n;
  34.     register int uc;
  35.  
  36.     if (size <= 0)
  37.         return(NULL);
  38.  
  39.     s = src;
  40.     d = dst;
  41.     uc = UNSCHAR(ucharstop);
  42.     for (n = size; n > 0; n--)
  43.         if (UNSCHAR(*(uchar *)d++ = *(uchar *)s++) == uc)
  44.             return(d);
  45.  
  46.     return(NULL);
  47. }
  48.